//
//  GuiderSectionHeadView.m
//  ImGuider
//
//  Created by 李陆涛 on 2018/1/4.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "GuiderSectionHeadView.h"
@interface GuiderSectionHeadView ()

@property (weak, nonatomic) IBOutlet UIButton *lineBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineBtnWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineBtnTrailing;
@property (weak, nonatomic) IBOutlet UIButton *specialBtn;

@property (weak, nonatomic) IBOutlet UIButton *bigBtn;
@property (weak, nonatomic) IBOutlet UIButton *smallBtn;

@property (strong, nonatomic) UIView *tagView;
@end

@implementation GuiderSectionHeadView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    
    [self.lineBtn setTitle:MYLocalizedString(@"HOME_RECORD", nil) forState:UIControlStateNormal];
    [self.specialBtn setTitle:MYLocalizedString(@"HOME_THEME", nil) forState:UIControlStateNormal];
    self.tagView = [UIView new];
    self.tagView.backgroundColor = kThemeColor;
    [self addSubview:self.tagView];
    
    [self.tagView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.mas_bottom).offset(-5);
        make.centerX.equalTo(self.lineBtn.mas_centerX);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(2);
        
    }];
    
    [self.lineBtn setTitleColor:kThemeColor forState:UIControlStateSelected];
    [self.specialBtn setTitleColor:kThemeColor forState:UIControlStateSelected];
    [self.bigBtn setTitleColor:kThemeColor forState:UIControlStateSelected];
    [self.smallBtn setTitleColor:kThemeColor forState:UIControlStateSelected];
    
    self.bigBtn.selected = YES;
    self.smallBtn.selected = NO;
    
    self.lineBtn.selected = YES;
    self.specialBtn.selected = NO;
}


- (void)setTypeArray:(NSArray *)typeArray {
    
    _typeArray = typeArray;
    
    if (typeArray.count != 1 ) {
        return;
    }
    
    NSString *type = [typeArray firstObject];
    self.tagView.hidden = YES;
    
    if ([type isEqualToString:@"line"]) {
        
        self.specialBtn.hidden = YES;
        
    } else {
        
        self.lineBtn.hidden = YES;
        self.lineBtnWidth.constant = 0;
        self.lineBtnTrailing.constant = -8;
        
    }
}

- (void)setIsSelectLine:(BOOL)isSelectLine {
    
    _isSelectLine = isSelectLine;
    
    if (isSelectLine) {
        [self makeAnimation:self.lineBtn];
        
        self.lineBtn.selected = YES;
        self.specialBtn.selected = NO;
    } else {
        
        [self makeAnimation:self.specialBtn];
        
        self.lineBtn.selected = NO;
        self.specialBtn.selected = YES;
    }
}

- (IBAction)showSmallAction:(id)sender {
    
    [_delegate changeTypeWithType:1];
    
    self.bigBtn.selected = NO;
    self.smallBtn.selected = YES;
}
- (IBAction)showBigAction:(id)sender {
    
    [_delegate changeTypeWithType:0];
    
    self.bigBtn.selected = YES;
    self.smallBtn.selected = NO;
}
- (IBAction)lineAction:(id)sender {
    
    [self makeAnimation:sender];
    
    [_delegate changeTypeWithType:2];
    self.lineBtn.selected = YES;
    self.specialBtn.selected = NO;
}
- (IBAction)sepcialAction:(id)sender {
    
    [self makeAnimation:sender];
    
    [_delegate changeTypeWithType:3];
    self.lineBtn.selected = NO;
    self.specialBtn.selected = YES;
}

- (void)makeAnimation:(UIView *)toView {
    
    if (!toView) {
        return;
    }

    [self.tagView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.mas_bottom).offset(-5);
        make.centerX.equalTo(toView.mas_centerX);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(2);
    }];
    
}

@end

